function getCookie(req, cname) {
  let name = cname + "=";
  try {
    let ca = req.headers.cookie.split(";");
    for (let i = 0; i < ca.length; i++) {
      let c = ca[i].trim();
      if (c.indexOf(name) === 0) return c.substring(name.length, c.length);
    }
  } catch (error) {
    return ''
  }
}

function createCookie(cname, cValue, exTimes) {
  let d = new Date();
  d.setTime(d.getTime() + exTimes * 60 * 1000);
  let expires = "expires=" + d.toGMTString();
  return cname + "=" + cValue + "; " + expires + "path=./";
}

module.exports={
  getCookie:getCookie,
  createCookie:createCookie
}